package com.hospital.spd.service.impl;

import com.hospital.spd.dao.ReportMapper;
import com.hospital.spd.pojo.ReportBusinessDO;
import com.hospital.spd.pojo.ReportDetailDO;
import com.hospital.spd.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author heghai
 */
@Service
public class ReportServiceImpl implements ReportService {


    @Autowired
    ReportMapper reportMapper;

    /**
     * 查询报表退货信息,包含2退1和退供应商明细
     *
     * @return
     */
    @Override
    public Map<String,List<ReportDetailDO>> selectDetails() {
        List<ReportDetailDO> list = reportMapper.selectDetails();
        List<ReportDetailDO> listToVender = new ArrayList<>();
        List<ReportDetailDO> listToStore = new ArrayList<>();
        for (ReportDetailDO item : list) {
            if (item.getMark().equals("tow退1明细")) {
                listToStore.add(item);
            }else {
                listToVender.add(item);
            }
        }


        Map<String,List<ReportDetailDO>> map = new HashMap<>(16);
        map.put("tow退1明细",listToStore);
        map.put("退供应商明细",listToVender);
        return map;
    }

    /**
     * 查询出入库业务数量及金额
     *
     * @return
     */
    @Override
    public Map<String,ReportBusinessDO> selectBusiness() {
        List<ReportBusinessDO> list = reportMapper.selectBusiness();
        Map<String, ReportBusinessDO> map = new HashMap<>(16);
        String key = "";
        for(ReportBusinessDO item : list) {
            key = item.getMark();
            if (key != null) {
                map.put(key,item);
            }
        }
        return map;
    }

    /**
     * 查询动态数据部分,包含动盘及今日出入库,库存,期末总数
     *
     * @return
     */
    @Override
    public Map<String,ReportBusinessDO> selectDynData() {
        List<ReportBusinessDO> list = reportMapper.selectDynData();
        Map<String,ReportBusinessDO> map = new HashMap<>(16);
        String key = "";
        for (ReportBusinessDO item : list) {
            if (key != null) {
                map.put(item.getMark(),item);
            }
        }
        return map;
    }

    /**
     * 查询发票数据明细
     *
     * @return
     */
    @Override
    public List<ReportBusinessDO> selectInvoice() {
        return reportMapper.selectInvoice();
    }
}
